package york.Game;

public class Clock {

	/*
	 * TotalGameTime is the time since the game started
	 * IntervalLength is how long the game waits before it is told it needs
	 *  to update again
	 * CurrentIntervalTime is how long it has been since the last update
	 */
	long TotalAppTime;
	double IntervalLength;
	double CurrentIntervalTime;
	double CurrentTimeLapse;
	double OldTime;
	boolean UpdateNow;
	
	public Clock(long a_IntervalLength) {
		TotalAppTime = 0;
		IntervalLength = a_IntervalLength;
		CurrentIntervalTime = 0;
		OldTime = System.currentTimeMillis();
		UpdateNow = false;
	}
	
	public void update() {
		long NewTime = System.currentTimeMillis();
		CurrentTimeLapse = NewTime - OldTime;
		CurrentIntervalTime += CurrentTimeLapse;
		TotalAppTime += CurrentTimeLapse;
		if( CurrentIntervalTime >= IntervalLength ) {
			UpdateNow = true;
			CurrentIntervalTime = 0;
		}
		OldTime = NewTime;
	}

	public long GetTotalTime() {
		return TotalAppTime;
	}
	public boolean TimeToUpdate() {
		return UpdateNow;
	}

	public void Updated() {
		UpdateNow = false;
	}

	public double getInterval() {
		return CurrentIntervalTime;
	}

	public double getLastTimeLapse() {
		return CurrentTimeLapse;
	}

}
